package com.zimmor.mq.rocket_train.batch;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.util.*;

/**
 * @Author:zimmor
 * @Date: 2023/2/14 10:23
 * @Description 批量发送生产者
 * @version: 1.0.0
 */

public class Producer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        //创建成产者
        DefaultMQProducer producer = new DefaultMQProducer("producer-group4");
        //设置namesrv
        producer.setNamesrvAddr("192.168.204.136:9876;192.168.204.137:9876");
        //启动producer
        producer.start();
        //构建message
        List<Message> list =new ArrayList<Message>();
        list.add(new Message("batch", "TAG","BatchMessage01".getBytes()));
        list.add(new Message("batch", "TAG","BatchMessage02".getBytes()));
        list.add(new Message("batch", "TAG","BatchMessage03".getBytes()));
        //发送message
        SendResult sendResult = producer.send(list);
        System.out.println("sendResult = " + sendResult);
        //关闭concumer
        producer.shutdown();
    }
}
